package huaweiod.first;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;

/**
 * 华为OD机试真题 Java 实现【区间交叠问题】【2022.11 Q4新题】
 */
public class A_2023_22_MinSection {

    public static void main(String[] args) {
        // 处理输入
        Scanner in = new Scanner(System.in);
        int count = Integer.parseInt(in.nextLine());

        //自定义排序
        Integer[][] ranges = new Integer[count][];
        for (int i = 0; i < count; i++) {
            ranges[i] = Arrays.stream(in.nextLine().split(",")).map(Integer::parseInt).toArray(Integer[]::new);
        }
        // 按线段排序
        Arrays.sort(ranges, (a, b) -> a[0] - b[0]);
        LinkedList<Integer[]> linkedList = new LinkedList<>();
        linkedList.add(ranges[0]);

        for (int i = 1; i < ranges.length; i++) {
            int s1 = ranges[i][0];
            int e1 = ranges[i][1];
            while (true) {
                if (linkedList.size() == 0) {
                    linkedList.add(ranges[i]);
                    break;
                }
                Integer[] last = linkedList.getLast();
                int s0 = last[0];
                int e0 = last[1];
                if (s1 < s0) {
                    if (e1 < s0) {
                        break;
                    } else if (e1 <= e0) {
                        break;
                    } else {
                        linkedList.removeLast();
                    }
                } else if (s1 <= e0) {
                    if (e1 <= e0) {
                        break;
                    } else {
                        linkedList.add(new Integer[]{e1, e0});
                        break;
                    }
                } else {
                    linkedList.add(ranges[i]);
                    break;
                }
            }
        }
        System.out.println(linkedList.size());
    }
}
